#include "lan2callineedit.h"

#include <QEvent>
#include <QMouseEvent>
#include <QDebug>
#include <QIntValidator>
#include <QTimer>

LAN2STA
Lan2CalLineEdit::Lan2CalLineEdit(int width, int height, QWidget *parent)
    :QLineEdit(parent)
{
    this->setFixedSize(width,height);
    this->setStyleSheet("QLineEdit{border:1px solid #cccccc}");
    this->setReadOnly(true);
    QIntValidator* val=new QIntValidator(this);
    this->setValidator(val);
    this->setMaxLength(2);


    this->setStyle(new HideCursorStyle());
    this->setAlignment(Qt::AlignHCenter);


    this->installEventFilter(this);

}

void Lan2CalLineEdit::method_setText(const QString &txt)
{
 this->setText(txt);
}

bool Lan2CalLineEdit::eventFilter(QObject *watched, QEvent *event)
{
    if(watched==this && event->type()==QEvent::MouseButtonPress){
        QMouseEvent* eve=(QMouseEvent*)event;
        if(eve->buttons()==Qt::LeftButton){
            this->setReadOnly(false);


            if(this->objectName()=="le_hh"){

              emit sign_hhclick();
            }else if(this->objectName()=="le_mm"){
                emit sign_mmclick();
            }else if(this->objectName()=="le_ss"){
                emit sign_ssclick();
            }
//            QTimer::singleShot(0,[=]()mutable{this->selectAll(); });
        }

    }

//    if(watched==this && event->type()==QEvent::FocusIn){


//        this->setReadOnly(false);
//        QTimer::singleShot(0,[=]()mutable{this->selectAll(); });


//        if(this->objectName()=="le_hh"){

//        }


//    }

//    return QLineEdit::eventFilter(watched,event);
}

LAN2END
